<?php
/**
 * Created by PhpStorm.
 * User: yafex
 * Date: 2021/4/19
 * Time: 11:03
 */

class serv_rapi_tencent extends L {

    private static $secretId = 'AKID5vU9Zi8HUZO1ILkFo7Ayvd5HH0TfpU6R';

    private static $secretKey = 'lIYWEfphTzDApDWZKnzvb07MMfiUNgjm';

    /**
     * 描述 : 签名串组规则
     * 作者 : Zoro.Zhu
     */
    public static function apiSign($codeArr, $apiUrl, $appSecret) {
        ksort($codeArr);
        foreach ($codeArr as $key => $val) {
            $apiUrl .= $key . '=' . $val . '&';
        }
        return base64_encode(hash_hmac('sha1', trim($apiUrl , '&'), $appSecret, true));
    }

    /**
     * 描述 : 国外发送短信
     * 作者 : Zoro.Zhu
     */
    public static function sendSms($params = []){
        $url = "https://sms.tencentcloudapi.com/?";
        $array = [
            'Action' => 'SendSms',
            'Version' => '2019-07-11',
            'PhoneNumberSet.0' => '+', //电话号码
            //            'PhoneNumberSet.1' => '+8618620337050',
            'TemplateID' => '928958', //927436  //模板ID
            'SmsSdkAppid' => '1400508364',
            //            'Sign' => '六束光',
            'TemplateParamSet.0' => 'Wine Wood Chandeliers Lamp',
            'TemplateParamSet.1' => 'LZ775364431CN',
            'TemplateParamSet.2' => 'LZ809795716CN',
            'Timestamp' => time(),
            'Nonce' => rand(0,100),
            'SecretId' => self::$secretId,
        ];
        $signStr = self::apiSign($array, 'GETsms.tencentcloudapi.com/?', self::$secretKey);
        $array['Signature'] = $signStr;
        ksort($array);
        $data = http_build_query($array);
        $res =  of_base_com_net::request($url . $data);
        p(json_decode($res['response'], true));
    }

    /**
     * 描述 : 国内发送短信
     * 作者 : Zoro.Zhu
     */
    public static function sendSms2($params = []){
        $url = "https://sms.tencentcloudapi.com/?";
        $array = [
            'Action' => 'SendSms',
            'Version' => '2019-07-11',
            'PhoneNumberSet.0' => '+8615013677786', //电话号码
            //            'PhoneNumberSet.1' => '+8618620337050',
            'TemplateID' => '927436', //  //模板ID
            'SmsSdkAppid' => '1400508364',
            'Sign' => '六束光',
            'TemplateParamSet.0' => '7pcs Drill Bit Chisel 6-12.7mm Auger Tool Set',
            'TemplateParamSet.1' => 'LZ794315671CN',
            'TemplateParamSet.2' => 'LZ802464989CN',
            'Timestamp' => time(),
            'Nonce' => rand(0,100),
            'SecretId' => self::$secretId,
        ];
        $signStr = self::apiSign($array, 'GETsms.tencentcloudapi.com/?', self::$secretKey);
        $array['Signature'] = $signStr;
        ksort($array);
        $data = http_build_query($array);
        $res =  of_base_com_net::request($url . $data);
        p(json_decode($res['response'], true));
    }

}
return true;